<include file="Common/common" />

<body>
	
	<div class="layui-tab-item layui-show">
		<div class="layui-main">
			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			  	<legend  style="color: rgb(240,222,112)" >个人资料</legend>
			</fieldset>

			<form class="layui-form"  action="" style="color: rgb(240,222,112)">
				<div class="layui-form-item">
					<div  class="layui-form-mid layui-word-aux"><span style="color: rgb(240,222,112)">为了您的账号安全，请务必使用真实资料；支付宝，微信,银行卡至少要填写一项，开户名和姓名保持一致！</span></div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">邀请二维码</label>
					<div class="layui-upload-list" style="margin-left: 110px;">
						<img class="layui-upload-img"  src="{$qrcode}" >
						
					</div>
					
				</div>

				<div class="layui-form-item">
					<label style="color: rgb(240,222,112)" class="layui-form-label">邀请链接</label>
					<div style="color: rgb(240,222,112)" class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="text" value="{$promote}" lay-verify="required"  autocomplete="off" class="layui-input" disabled="">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">会员账号</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="text" value="{$userInfo['account']}" lay-verify="required"  autocomplete="off" class="layui-input" disabled="">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">真实姓名</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="text"  name="truename" value="{$userInfo['truename']}"  autocomplete="off" lay-verify="required" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">手机号码</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="text"  name="phone" value="{$userInfo['phone']}"  autocomplete="off" lay-verify="required|phone" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">开户行名称</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="text"  name="bankname" value="{$userInfo['bankname']}"  autocomplete="off"  class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">网银资料</label>
					<div class="layui-input-block">
						<input  style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="text"  name="bankcard" value="{$userInfo['bankcard']}"  autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">支付宝收款账号</label>
					<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="hidden" id="alipay_img_url" name="alipay_img_url" value="{$userInfo['alipay_url']}">
					<div class="layui-upload">
						<button style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  type="button" class="layui-btn" id="upload-alipay-pic">添加图片</button>

					</div>
					<div class="layui-upload-list" style="margin-left: 110px;">
						<img class="layui-upload-img" id="alipay-pic" <if condition="$userInfo['alipay_url'] neq ''"> src="{$userInfo['alipay_url']}"</if> >
						<p id="demoAlipayText"></p>
					</div>
					
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">微信收款账号</label>
					<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="hidden" id="wx_img_url" name="wx_img_url" value="{$userInfo['wx_url']}">
					<div class="layui-upload">
						<button style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  type="button" class="layui-btn" id="upload-wx-pic">添加图片</button>
						
					</div>
					<div class="layui-upload-list" style="margin-left: 110px;">
						<img class="layui-upload-img" id="wx-pic" <if condition="$userInfo['wx_url'] neq ''">src="{$userInfo['wx_url']}"</if> >
						<p id="demoWxText"></p>
					</div>
					
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block" style="margin-left: 105px;">
						<button style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  class="layui-btn" lay-submit="" lay-filter="btn-changeInfo">上传</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>	
<script type="text/javascript">
	layui.use(['upload','layedit'], function(){
		var form = layui.form,
		layer = layui.layer,
		layedit = layui.layedit;

		var $ = layui.jquery
		,upload = layui.upload;


		form.render();

		//监听提交表单
		form.on('submit(btn-changeInfo)', function(data){
			if (data.field.bankcard == '' && data.field.alipay_img_url == '' && data.field.wx_img_url == '') {
                layer.msg('<span style="color: rgb(240,222,112);">银行卡，支付宝，微信至少填写一项</span>');
				return false;
			}

			if (data.field.bankname.trim() != '' && data.field.bankcard.trim() == '') {
                layer.msg('<span style="color: rgb(240,222,112);">网银资料不能为空/span>');
				return false;
			}

			if (data.field.bankname.trim() == '' && data.field.bankcard.trim() != '') {
                layer.msg('<span style="color: rgb(240,222,112);">开户行不能为空</span>');
				return false;
			}

			layer.confirm('确定要保存？',{offset:'none'},function(index){
				$.ajax({
		            type: "post",
		            url: "{:U('Personal/ctrl_changeInfo')}",
		            data: data.field,
		            dataType: "json",
		            success: function(rtJson){
                        layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
		            }
		        });
			});
			
	        return false;
		});


		//微信图片上传
		var uploadInstWx = upload.render({
			elem: '#upload-wx-pic',
			url: "{:U('Common/UploadPic')}",
			before: function(obj){
				//预读本地文件示例，不支持ie8
				obj.preview(function(index, file, result){
					$('#wx-pic').attr('src', result); //图片链接（base64）
				});
			},
			done: function(res){
				
				if(res.code == 1){
					//上传成功
					document.getElementById("wx_img_url").value = res.url;
                    return layer.msg('<span style="color: rgb(240,222,112);">上传成功</span>');
				}else{
					//如果上传失败
                   	return layer.msg('<span style="color: rgb(240,222,112);">上传失败</span>');
				}
				
			},
			error: function(){
				//演示失败状态，并实现重传
				var demoText = $('#demoWxText');
				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
				demoText.find('.demo-reload').on('click', function(){
					uploadInstWx.upload();
				});
			}
		});

		//支付宝图片上传
		var uploadInstAlipay = upload.render({
			elem: '#upload-alipay-pic',
			url: "{:U('Common/UploadPic')}",
			before: function(obj){
				//预读本地文件示例，不支持ie8
				obj.preview(function(index, file, result){
					$('#alipay-pic').attr('src', result); //图片链接（base64）
				});
			},
			done: function(res){
				
				if(res.code == 1){
					//上传成功
					document.getElementById("alipay_img_url").value = res.url;
					return layer.msg('上传成功');
				}else{
					//如果上传失败
					return layer.msg('上传失败');
				}
				
			},
			error: function(){
				//演示失败状态，并实现重传
				var demoText = $('#demoAlipayText');
				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
				demoText.find('.demo-reload').on('click', function(){
					uploadInstAlipay.upload();
				});
			}
		});

	});
</script>
<include file="Common/footer" />